
//转JAVA实体类
(function () {
	if (window.__tojavamodel_flg) {
		return;
	}
	window.__tojavamodel_flg = true;

	//转JAVA实体类
	function toJavaModel(content) {
		var str = '';
		var fieldsContent = '';

		var lines = content.split('\n');
		lines.forEach(line => {
			var values = line.split('\t');
			var filedName = values[0];
			var desc = values[1];
			var sqldbType = values[2];
			var javaType = sqlTypetoJavaType(sqldbType);
			fieldsContent += `
	/**
     * ${desc}
     */
	@TableField(value = "${filedName}")
	private ${javaType} ${camelCase(filedName)};
		`;

		});


		str = `
/**
 * 
 * @author 
 * @date ${new Date().Format('yyyy/MM/dd')}
 */	
@Data
@TableName("")
public class xxxDO {
	${fieldsContent}
}`;
		//console.log(str);
		//copy(str);
		return str;
	}

	//数据库数据类型转JAVA数据类型
	function sqlTypetoJavaType(sqlType) {
		var map = {
			'int': 'Integer',
			'varchar': 'String',
			'datetime': 'Date',
			'date': 'Date',
			'numeric': 'BigDecimal',
			'money': 'BigDecimal',
			'decimal': 'BigDecimal',
		};
		sqlType = sqlType.toLowerCase();
		return map[sqlType] || 'UNKONW';
	}

	//下划线转驼峰
	function camelCase(string) {
		string = string.replace('rowid', 'id');
		return string.replace(/_\w/g, function (all, letter) {
			return all.substr(1).toUpperCase();
		});
	}

	window.toJavaModel = toJavaModel;

})();
